package ${package.Controller};


import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bone.common.vo.Result;
import java.util.Arrays;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * ${table.comment!} 前端控制器
 *
 * @author : ${author}
 * @date : ${date}
 *
 */
<#if restControllerStyle>
@Api(tags = {"${table.comment!}"})
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
public class ${table.controllerName} {
    </#if>
    @Autowired
    private ${table.serviceName} ${(table.serviceName?substring(1))?uncap_first};

    /**
     * 查询分页数据
     */
    @ApiOperation(value = "查询分页数据")
    @GetMapping(value = "/page")
    public Result<Page<${entity}>> findListByPage(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize){
        return Result.ok(${(table.serviceName?substring(1))?uncap_first}.page(new Page<>(pageNo,pageSize)));
    }


    /**
    * 根据id查询
    */
    @ApiOperation(value = "根据id查询数据")
    @GetMapping(value = "/getById")
    public Result<${entity}> getById(@RequestParam("id") String id){
        return Result.ok(${(table.serviceName?substring(1))?uncap_first}.getById(id));
    }

    /**
    * 新增
    */
    @ApiOperation(value = "新增数据")
    @PostMapping(value = "/add")
    public Result<${entity}> add(@RequestBody ${entity} ${entity?uncap_first}){
        return ${(table.serviceName?substring(1))?uncap_first}.save(${entity?uncap_first}) ? Result.ok() : Result.error("添加失败");
    }

    /**
    * 删除
    */
    @ApiOperation(value = "删除数据")
    @DeleteMapping(value = "/del")
    public Result<String> delete(@RequestParam("ids") String ids){
        return ${(table.serviceName?substring(1))?uncap_first}.removeByIds(Arrays.asList(ids.split(","))) ? Result.ok() : Result.error("删除失败");
    }

        /**
        * 修改
        */
    @ApiOperation(value = "更新数据")
    @PutMapping(value = "/update")
    public Result<${entity}> update(@RequestBody ${entity} ${entity?uncap_first}){
        return ${(table.serviceName?substring(1))?uncap_first}.updateById(${entity?uncap_first}) ? Result.ok() : Result.error("更新失败");
    }

}
</#if>